#ifndef QXGAME_SINGLETONPTR_H
#define QXGAME_SINGLETONPTR_H

#include <memory>
#include <mutex>

template<typename T>
class SingletonPtr {
public:
    SingletonPtr(const SingletonPtr &) = delete;
    SingletonPtr(const SingletonPtr &&) = delete;
    SingletonPtr &operator=(const SingletonPtr &) = delete;
    SingletonPtr &operator=(const SingletonPtr &&) = delete;

    static T &Instance()
    {
        static std::once_flag singletonFlag;
        std::call_once(singletonFlag, [&] {
            instance = std::make_shared<T>();
        });
        return instance;
    }

protected:
    SingletonPtr() = default;
    ~SingletonPtr() = default;
    static std::shared_ptr<T> instance = nullptr;
};
#endif // QXGAME_SINGLETONPTR_H
